// 播放列表类
import java.util.ArrayList;
import java.util.List;

class Playlist {
    private final List<AudioFile> audioFiles = new ArrayList<>();
    private int currentIndex = -1;

    public void add(AudioFile audioFile) {
        audioFiles.add(audioFile);
    }

    public void remove(int index) {
        if (index >= 0 && index < audioFiles.size()) {
            if (index == currentIndex) {
                currentIndex = -1;
            } else if (index < currentIndex) {
                currentIndex--;
            }
            audioFiles.remove(index);
        }
    }

    public AudioFile get(int index) {
        if (index >= 0 && index < audioFiles.size()) {
            return audioFiles.get(index);
        }
        return null;
    }

    public AudioFile getCurrent() {
        if (currentIndex >= 0 && currentIndex < audioFiles.size()) {
            return audioFiles.get(currentIndex);
        }
        return null;
    }

    public int getSize() {
        return audioFiles.size();
    }

    public int getCurrentIndex() {
        return currentIndex;
    }

    public void setCurrentIndex(int index) {
        if (index >= 0 && index < audioFiles.size()) {
            this.currentIndex = index;
        }
    }

    public AudioFile next() {
        if (audioFiles.isEmpty()) {
            return null;
        }
        currentIndex = (currentIndex + 1) % audioFiles.size();
        return audioFiles.get(currentIndex);
    }

    public AudioFile previous() {
        if (audioFiles.isEmpty()) {
            return null;
        }
        currentIndex = (currentIndex - 1 + audioFiles.size()) % audioFiles.size();
        return audioFiles.get(currentIndex);
    }
}